<?php

	/*
		Jax Calendar v1.34 - Copyright (c) 2002-2004, Andreas John aka Jack (tR)
		This program and it's moduls are Open Source in terms of General Public Licens (GPL) v2.0

		main.inc.php 		(diverse functions needed by calendar modules)
	*/
	
	
    // fit if nescessary:
#	define( "PATH_TO_SCRIPT", "../" );
	
	if (empty($base_url["jax_cal"])) $base_url["jax_cal"] = ".";

	if (!empty( $_SERVER["PHP_SELF"] )) $PHP_SELF = $_SERVER["PHP_SELF"];
		
    // freeze time! ;-)
	$now = gmmktime();
	$now_year  = intval( gmdate( "Y", $now ) );
	$now_month = intval( gmdate( "m", $now ) );
	$now_day   = intval( gmdate( "d", $now ) );
	$now_hour  = gmdate( "H", $now );
	$now_min   = gmdate( "i", $now );
	$now_sec   = gmdate( "s", $now );

	// load global settings
	require ( dirname(__FILE__) . "/".PATH_TO_SCRIPT."settings/calendar.settings.inc.php");

	// include localisation file for the favoured language (if exists)
	if ( file_exists( "languages/" . $language . ".inc.php" ) )
		define( "LOC_LANG", $language ); 
	else
		define( "LOC_LANG", $default_language ); 

	require_once ( dirname(__FILE__) ."/".PATH_TO_SCRIPT."languages/" . LOC_LANG . ".inc.php" );

	echo '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'">';
	echo '<link rel="stylesheet" href="'.$base_url["jax_cal"]."/".$css_file.'">'."\n";	
	
	if ( $data_source == "mysql" )
	{
		
		// include class for database support
		require_once ( dirname(__FILE__) . "/"."classes/mysql.inc.php" );
		
		// prepare objects for database access
		// list of subscribers which signed in/off
		$calendar_list           = new mysql;
		$calendar_list->name     = $calendar_file;
		$calendar_list->server   = $db_server;
		$calendar_list->login    = $db_login;
		$calendar_list->password = $db_password;
		$calendar_list->database = $db_database;
		$calendar_list->init();
		$calendar_list->order_criterion = "ORDER BY 'event_start' DESC";

		$event_list           = new mysql;
		$event_list->name     = $event_file;
		$event_list->server   = $db_server;
		$event_list->login    = $db_login;
		$event_list->password = $db_password;
		$event_list->database = $db_database;
		$event_list->init();
	}

	if ( $data_source == "csvfile" )
	{
		// include class for CSV-textfile support
		require_once ( dirname(__FILE__) . "/"."classes/csvfile.inc.php" );

		// prepeare objects for file access
		// list of subscribers which signed in/off
		$calendar_list        = new csvfile;
		$calendar_list->name  = dirname(__FILE__) . "/".PATH_TO_SCRIPT.'cal_data/'.$calendar_file;

		$calendar_list->init();
		
		$event_list        = new csvfile;
		$event_list->name  = dirname(__FILE__) . "/".PATH_TO_SCRIPT.'cal_data/'.$event_file;
		$event_list->init();
	}

	if ( !empty( $_GET[ "Y" ] ) ) $cal_year = $_GET[ "Y" ];  else $cal_year = $now_year;
	if ( !empty( $_GET[ "m" ] ) ) $cal_month = $_GET[ "m" ]; else $cal_month = $now_month;
	if ( !empty( $_GET[ "d" ] ) ) $cal_day = $_GET[ "d" ];   else $cal_day = $now_day;
	
	if ( !empty( $_GET[ "gmt_ofs" ] ) ) $GMT_ofs = $_GET[ "gmt_ofs" ]; 
	if ( !empty( $_GET[ "view"]  ) )    $view = $_GET[ "view" ]; else $view = $view_default;
	
	$ox_tail = "cal_id=$cal_id&language=$language&gmt_ofs=$GMT_ofs&view=$view";
	
	// calc following month and year
	$cal_next_year = $cal_year;
	if ( $cal_month < 12 )
	{
		$cal_next_month = $cal_month + 1;
	} 
	else 
	{
		$cal_next_month = 1;
		$cal_next_year = $cal_year + 1;
	}
	
	// calc previous month and year
	$cal_prev_year = $cal_year;
	if ( $cal_month > 1 )
	{
		$cal_prev_month = $cal_month - 1;
	} 
	else 
	{
		$cal_prev_month = 12;
		$cal_prev_year = $cal_year - 1;
	}	
		
	/**
	* @return integer
	* @param  string $year
	* @param  string $month
	* @desc   returns count of days for specified month/year
	*/
	function num_days( $year, $month )
	{
		$num = 31;
		while (!checkdate( $month, $num, $year ) ) { $num--; }
		return $num;	
	}
	
	
	
?>
